//package com.kapcb.mvc.validator;
//
//import cn.hutool.core.collection.CollUtil;
//import com.kapcb.common.constant.StringPool;
//import lombok.experimental.UtilityClass;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.util.Assert;
//
//import javax.validation.ConstraintViolation;
//import javax.validation.ConstraintViolationException;
//import javax.validation.Validation;
//import javax.validation.Validator;
//import java.util.Set;
//import java.util.regex.Pattern;
//
///**
// * <a>Title: ValidatorUtils </a>
// * <a>Author: kapcb <a>
// * <a>Description: ValidatorUtils <a>
// *
// * @author Kpacb
// * @version 1.0
// * @date 2024/5/1 15:02
// * @since 1.0
// */
//@UtilityClass
//public class ValidatorUtils {
//
//    private static final Pattern PATTERN_MOBILE = Pattern.compile(StringPool.MOBILE_REGEX);
//
//    private static final Pattern PATTERN_URL = Pattern.compile(StringPool.URL_REGEX);
//
//    private static final Pattern PATTERN_XML_NCNAME = Pattern.compile("[a-zA-Z_][\\-_.0-9_a-zA-Z$]*");
//
//    public static boolean isMobile(String mobile) {
//        return StringUtils.isNotBlank(mobile)
//                && PATTERN_MOBILE.matcher(mobile).matches();
//    }
//
//    public static boolean isUrl(String url) {
//        return StringUtils.isNotBlank(url)
//                && PATTERN_URL.matcher(url).matches();
//    }
//
//    public static boolean isXmlNCName(String str) {
//        return StringUtils.isNotBlank(str)
//                && PATTERN_XML_NCNAME.matcher(str).matches();
//    }
//
//    public static void validate(Object object, Class<?>... groups) {
//        Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
//        Assert.notNull(validator);
//        validate(validator, object, groups);
//    }
//
//    public static void validate(Validator validator, Object object, Class<?>... groups) {
//        Set<ConstraintViolation<Object>> constraintViolations = validator.validate(object, groups);
//        if (CollUtil.isNotEmpty(constraintViolations)) {
//            throw new ConstraintViolationException(constraintViolations);
//        }
//    }
//
//}
